package com.blink.curator.operate;

import com.blink.base.BaseTestSample;
import org.apache.curator.framework.CuratorFramework;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.data.Stat;
import org.junit.jupiter.api.Test;

/**
 * <Description> 使用Curator删除节点</Description>
 * <ClassName> DeleteNodeSample</ClassName>
 *
 * @Author liuxianzhao
 * @Date 2018年01月13日 15:00
 */
public class DeleteNodeSample extends BaseTestSample {

    @Test
    public void testDeleteNode() throws Exception {
        CuratorFramework client = getZkCurator();
        client.start();
        String path = "/zk-book/c1";
        client.create()
                .creatingParentsIfNeeded()
                .withMode(CreateMode.EPHEMERAL)
                .forPath(path, "init".getBytes());
        Stat stat = new Stat();
        client.getData()
                .storingStatIn(stat)
                .forPath(path);
        client.delete()
                .deletingChildrenIfNeeded()
                .withVersion(stat.getVersion())
                .forPath(path);
        sleep();
    }
}
